package trabajoISW2.presentation.shared;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import trabajoISW2.domain.implementations.Book;
import trabajoISW2.domain.implementations.Cart;
import trabajoISW2.domain.implementations.Detail;

public class CartMapper {

	public static CartDTO createDTO(Cart c) {
		Book b;
		Detail d;
		DetailDTO ddto;
		BookDTO bdto;
		CartDTO dto = new CartDTO(new LinkedList<DetailDTO>(), c.getAmount());
		List<Detail> details = c.getDetails();
		Iterator<Detail> it = details.iterator();
		while (it.hasNext()) {
			d = it.next();
			b = d.getBook();
			bdto = new BookDTO(b.getIsbn(), b.getTitle(), b.getLanguage(),
					b.getAuthor().getName().concat(" "+b.getAuthor().getSurname()),
					b.getPublisher().getName(),
					b.getSubject().getName(), b.getSummary(),
					b.getPrice(), b.getYear());
			ddto = new DetailDTO(bdto, d.getQuantity());
			dto.getDetails().add(ddto);
		}
		return dto;
	}

	public static Cart updateDomainObject(List<Detail> details) {
		return new Cart(details);
		

	}

}
